package com.java3_9;

public class DishPut implements Runnable {
    private TotalDish dish;

    public DishPut() {

    }

    public DishPut(TotalDish dish) {
        this.dish = dish;
    }

    @Override
    public void run() {
        //为了使厨师不断提供菜，线程不终止
        while (true) {
            synchronized (TotalDish.class) {
                while (dish.getDish() >= 5) {
                    try {
                        TotalDish.class.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                dish.addDish();
                System.out.println(Thread.currentThread().getName() + "  又炒出了一份菜" + "现在一共有" + dish.getDish() + "份菜");
                TotalDish.class.notifyAll();;
            }
        }
    }
}
